import React from 'react';
import { connect } from 'react-redux';
import {addAction, subAction,asyncGetData} from '../store/actions';
 
class Home extends React.PureComponent{
    render(){
        const {increment,count,decrement,getAsyncData} = this.props
        return (
            <div>
                <p>{count}</p>
                <button onClick={increment}>递增</button>
                <button onClick={decrement}>递减</button>
                <button onClick={getAsyncData}>异步递增</button>
            </div>
        )
    }
}

const mapStateToProps = (state)=>{
    return{
        count: state.count
    }
}
const mapDispatchToProps = (dispatch)=>{
    return{
        increment(){
            dispatch(addAction(1));
        },
        decrement(){
            dispatch(subAction(2))
        },
        getAsyncData(){
            dispatch(asyncGetData(1))
        }
        
    }
}
export default connect(mapStateToProps, mapDispatchToProps)(Home);